<cfcomponent displayname="ticketService" output="false">

 	<cffunction name="init" returntype="any" output="false" hint="Constructor">
		<cfargument name="ORMService" type="any" required="true" />
		<cfset variables.instance.ORMService = arguments.ORMService/>
		<cfreturn this />
	</cffunction>

	<cffunction name="dumpvar" access="private" returntype="void">
		<cfargument name="davar" required="true">
	  <cfargument name="abort" default="true">
	  <cfdump var="#davar#">
	  <cfif arguments.abort>
		  <cfabort>
		</cfif>
	</cffunction>
	
	<cffunction name="getORMService" access="public" returntype="any" output="false" roles="" hint="">
		<cfreturn variables.instance.ORMService/>
	</cffunction>

	<cffunction name="GetEpochTime" access="public" returntype="any" hint="gets project">
		<cfscript>
			var datetime = 0;
			if (ArrayLen(Arguments) is 0) {
				datetime = Now();
		
			}
			else {
				if (IsDate(Arguments[1])) {
					datetime = Arguments[1];
				} else {
//					return NULL;
					return 0;
				}
			}
			return DateDiff("s", "January 1 1970 00:00", datetime);
		</cfscript>
	</cffunction>
			
	<cffunction name="getTicketComponentNames" access="public" returntype="any" hint="gets project">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="searchParams">
		<cfscript>
			var componentNames = structNew();
			var dataGW = getORMService().createGateway("projectcomponents");
			var query = dataGW.createquery();
			var retArray = arrayNew(1);
	 	  query.returnObjectFields("projectcomponents", "componentId,componentName,componentDescription,createUserId");
//			query.setFieldExpression("student","student_ID","COUNT(*)","CF_SQL_INTEGER");
 			query.getWhere().isEqual("projectcomponents", "projectId", arguments.projectId);
			query = dataGW.getByQuery(query);
	 	  componentNames = listToArray(valueList(query.componentName));
		  retArray[1] = componentNames;
		</cfscript>
    <cfreturn retArray>
	</cffunction>
	
	<cffunction name="getTicketComponent" access="public" returntype="any" hint="gets project">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="componentName">
		<cfscript>
			var retArray = arrayNew(1);
			var component = structNew();
			var componentRecord = getORMService().createRecord("projectcomponents").load(projectId=arguments.projectId,componentName=arguments.componentName);
		  component["name"] = componentRecord.getComponentName();
		  component["description"] = componentRecord.getComponentDescription();
		  component["owner"] = "$string" & componentRecord.getCreateUserId();
		  retArray[1] = component;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketMilestones" access="public" returntype="any" hint="gets project">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="searchParams">
		<cfscript>
			var milestoneNames = structNew();
			var dataGW = getORMService().createGateway("projectmilestones");
			var query = dataGW.createquery();
			var retArray = arrayNew(1);
	 	  query.returnObjectFields("projectmilestones", "milestoneId,milestoneName,milestoneDescription,createUserId");
 			query.getWhere().isEqual("projectmilestones", "projectId", arguments.projectId);
			query = dataGW.getByQuery(query);
	 	  milestoneNames = listToArray(valueList(query.milestoneName));
		  retArray[1] = milestoneNames;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketMilestone" access="public" returntype="any" hint="gets project">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="milestoneName">
		<cfscript>
			var retArray = arrayNew(1);
			var milestone = structNew();
			var milestoneRecord = getORMService().createRecord("projectmilestones").load(projectId=arguments.projectId,milestoneName=arguments.milestoneName);
			milestone["due"] = "$int" & GetEpochTime(milestoneRecord.getMilestoneDueDate());
			milestone["completed"] = "$int" & milestoneRecord.getMilestoneCompleted();
		  milestone["description"] = milestoneRecord.getMilestoneDescription();
		  milestone["name"] = milestoneRecord.getMilestoneName();
		  retArray[1] = milestone;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketPriorities" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="searchParams">
		<cfscript>
			var priorityNames = structNew();
			var dataGW = getORMService().createGateway("projectpriorities");
			var query = dataGW.createquery();
			var retArray = arrayNew(1);
	 	  query.returnObjectFields("projectpriorities", "priorityId,priorityName,priorityDescription,createUserId");
 			query.getWhere().isEqual("projectpriorities", "projectId", arguments.projectId);
			query = dataGW.getByQuery(query);
	 	  priorityNames = listToArray(valueList(query.priorityName));
		  retArray[1] = priorityNames;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketPriority" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<!--- return the number value for the priorty name? --->
		<cfargument name="priorityName">
		<cfscript>
			var retArray = arrayNew(1);
			var priorityRecord = getORMService().createRecord("projectpriorities").load(projectId=arguments.projectId,priorityName=arguments.priorityName);
		  retArray[1] = "$string" & priorityRecord.getPriorityId();
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketResolutions" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="searchParams">
		<cfscript>
			var resolutionNames = structNew();
			var dataGW = getORMService().createGateway("projectticketresolutions");
			var query = dataGW.createquery();
			var retArray = arrayNew(1);
	 	  query.returnObjectFields("projectticketresolutions", "resolutionId,resolutionName,resolutionDescription,createUserId");
 			query.getWhere().isEqual("projectticketresolutions", "projectId", arguments.projectId);
			query = dataGW.getByQuery(query);
	 	  resolutionNames = listToArray(valueList(query.resolutionName));
		  retArray[1] = resolutionNames;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketResolution" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="resolutionName">
		<cfscript>
			var retArray = arrayNew(1);
			var resolutionRecord = getORMService().createRecord("projectticketresolutions").load(projectId=arguments.projectId,resolutionName=arguments.resolutionName);
		  retArray[1] = "$string" & resolutionRecord.getResolutionId();
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketSeverities" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="searchParams">
		<cfscript>
			var severityNames = structNew();
			var dataGW = getORMService().createGateway("projectticketseverities");
			var query = dataGW.createquery();
			var retArray = arrayNew(1);
	 	  query.returnObjectFields("projectticketseverities", "severityId,severityName,severityDescription,createUserId");
 			query.getWhere().isEqual("projectticketseverities", "projectId", arguments.projectId);
			query = dataGW.getByQuery(query);
	 	  severityNames = listToArray(valueList(query.severityName));
		  retArray[1] = severityNames;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketSeverity" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="severityName">
		<cfscript>
			var retArray = arrayNew(1);
			var severityRecord = getORMService().createRecord("projectticketseverities").load(projectId=arguments.projectId,severityName=arguments.severityName);
		  retArray[1] = "$string" & severityRecord.getSeverityId();
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketStatuses" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="searchParams">
		<cfscript>
			var statusNames = structNew();
			var dataGW = getORMService().createGateway("projectticketstatuses");
			var query = dataGW.createquery();
			var retArray = arrayNew(1);
	 	  query.returnObjectFields("projectticketstatuses", "statusId,statusName,statusDescription,createUserId");
 			query.getWhere().isEqual("projectticketstatuses", "projectId", arguments.projectId);
			query = dataGW.getByQuery(query);
	 	  statusNames = listToArray(valueList(query.statusName));
		  retArray[1] = statusNames;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketStatus" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="statusName">
		<cfscript>
			var retArray = arrayNew(1);
			var statusRecord = getORMService().createRecord("projectticketstatuses").load(projectId=arguments.projectId,statusName=arguments.statusName);
		  retArray[1] = "$string" & statusRecord.getstatusId();
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketTypes" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="searchParams">
		<cfscript>
			var typeNames = structNew();
			var dataGW = getORMService().createGateway("projecttickettypes");
			var query = dataGW.createquery();
			var retArray = arrayNew(1);
	 	  query.returnObjectFields("projecttickettypes", "typeId,typeName,typeDescription,createUserId");
 			query.getWhere().isEqual("projecttickettypes", "projectId", arguments.projectId);
			query = dataGW.getByQuery(query);
	 	  typeNames = listToArray(valueList(query.typeName));
		  retArray[1] = typeNames;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketType" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="typeName">
		<cfscript>
			var retArray = arrayNew(1);
			var statusRecord = getORMService().createRecord("projecttickettypes").load(projectId=arguments.projectId,typeName=arguments.typeName);
		  retArray[1] = "$string" & statusRecord.getTypeId();
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketVersions" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="searchParams">
		<cfscript>
			var versionNames = structNew();
			var dataGW = getORMService().createGateway("projectversions");
			var query = dataGW.createquery();
			var retArray = arrayNew(1);
	 	  query.returnObjectFields("projectversions", "versionId,versionName,versionTime,versionDescription,createUserId");
 			query.getWhere().isEqual("projectversions", "projectId", arguments.projectId);
			query = dataGW.getByQuery(query);
	 	  versionNames = listToArray(valueList(query.versionName));
	 	  for(x = 1; x lte arrayLen(versionNames); x = x + 1) {
	 	   versionNames[x] = "$string" & versionNames[x];
	 	  }
		  retArray[1] = versionNames;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketVersion" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="versionName">
		<cfscript>
			var retStruct = structNew();
			var retArray = arrayNew(1);
			var versionRecord = getORMService().createRecord("projectversions").load(projectId=arguments.projectId,versionName=arguments.versionName);
		  retStruct["name"] = "$string" & versionRecord.getVersionName();
		  retStruct["description"] = "$string" & versionRecord.getVersionTime();
		  retStruct["time"] = "$int0" & GetEpochTime(versionRecord.getVersionTime());
		</cfscript>
		<cfset retArray[1] = retStruct>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketChangeLog" access="public" returntype="any" hint="">
		<cfargument name="params">
		<cfscript>
			var ticketChangeLog = arrayNew(2);
			var dataGW = getORMService().createGateway("projectticketcomments");
			var query = dataGW.createquery();
			var retArray = arrayNew(1);
	 	  query.returnObjectFields("projectticketcomments", "commentId,createDate,commentText,createUserId");
 			query.getWhere().isEqual("projectticketcomments", "ticketid", arguments.params[1]);
			query = dataGW.getByQuery(query);
	 	  for(x = 1; x lte query.recordcount; x = x + 1) {
	 	   ticketChangeLog[x][1] = "$int" & GetEpochTime(query["createDate"][x]);
	 	   ticketChangeLog[x][2] = "$string" & query["createUserId"][x];
	 	   ticketChangeLog[x][3] = "$string" & "comment";
	 	   ticketChangeLog[x][4] = "$string" & "1"; // oldvalue?
	 	   ticketChangeLog[x][5] = "$string" & query["commentText"][x]; // newvalue?
	 	   ticketChangeLog[x][6] = "$string" & "1"; // permanent?
	 	  }
			  retArray[1] = ticketChangeLog;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketRecentChanges" access="public" returntype="any" hint="">
	  <cfset var myArray = arrayNew(1)>
	  <cfset var componentNames = arrayNew(1)>
	  <cfset var rpcCall = "">
	  <cfset componentNames[1] = "$int1">
	  <cfset myArray[1] = componentNames>
    <cfreturn myArray>
	</cffunction>

	<cffunction name="listTicketAttachments" access="public" returntype="any" hint="">
		<cfargument name="params">
		<cfscript>
			var ticketAttachments = arrayNew(2);
			var dataGW = getORMService().createGateway("projectticketattachments");
			var query = dataGW.createquery();
			var retArray = arrayNew(1);
	 	  query.returnObjectFields("projectticketattachments", "attachmentId,createDate,attachmentFileName,attachmentDescription,attachmentFileSize,createUserId");
 			query.getWhere().isEqual("projectticketattachments", "ticketid", arguments.params[1]);
			query = dataGW.getByQuery(query);
	 	  for(x = 1; x lte query.recordcount; x = x + 1) {
	 	   ticketAttachments[x][1] = "$string" & query["attachmentFileName"][x];
	 	   ticketAttachments[x][2] = "$string" & query["attachmentDescription"][x];
	 	   ticketAttachments[x][3] = "$int" & query["attachmentFileSize"][x];
	 	   ticketAttachments[x][4] = "$int" & GetEpochTime(query["createDate"][x]);
	 	   ticketAttachments[x][5] = "$string" & query["createUserId"][x];
	 	  }
		  retArray[1] = ticketAttachments;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="ticketPutAttachment" access="public" returntype="any" hint="">
		<cfargument name="params">
		<cfscript>
			var attachmentRecord = getORMService().createRecord("projectticketattachments");
			attachmentRecord.setTicketId(arguments.params[1]);
			attachmentRecord.setAttachmentFileName(arguments.params[2]);
			attachmentRecord.setAttachmentDescription(arguments.params[3]);
			attachmentRecord.setAttachmentFileData(toBase64(arguments.params[4]));
			attachmentRecord.setAttachmentFileSize(len(arguments.params[4]));
			attachmentRecord.setCreateDate(now());
			attachmentRecord.setCreateUserId(3);
			attachmentRecord.setModifiedDate(now());
			//TODO: overwrite = arguments.params[4];
			attachmentRecord.save();
		</cfscript>
		<cfreturn attachmentRecord.getAttachmentFileName()>
	</cffunction>

	<cffunction name="viewTicketAttachment" access="public" returntype="any" hint="">
		<cfargument name="ticketId">
		<cfargument name="attachmentFileName">
		<cfscript>
			var attachmentRecord = getORMService().createRecord("projectticketattachments").load(ticketId=arguments.ticketId,attachmentFileName=arguments.attachmentFileName);
			var cvalue = "";
		</cfscript>
		<cfif isDefined('url.d')>
		 <cfset cvalue = 'attachment;'>
		</cfif>
		<cfset cvalue = cvalue & "filename=""#attachmentRecord.getAttachmentFileName()#""">
		<cfoutput><cfcontent type="text/plain" reset="true"><cfheader name="Content-Disposition" value="#cvalue#">#toString(toBinary(attachmentRecord.getAttachmentFileData()))#</cfoutput><cfabort>
	</cffunction>

	<cffunction name="getTicketAvailableActions" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="searchParams">
		<cfscript>
			var actionNames = structNew();
			var dataGW = getORMService().createGateway("projectticketactions");
			var query = dataGW.createquery();
			var retArray = arrayNew(1);
	 	  query.returnObjectFields("projectticketactions", "actionId,actionName,actionDescription,createUserId");
 			query.getWhere().isEqual("projectticketactions", "projectId", arguments.projectId);
			query = dataGW.getByQuery(query);
	 	  actionNames = listToArray(valueList(query.actionName));
		  retArray[1] = actionNames;
		</cfscript>
    <cfreturn retArray>
	</cffunction>

	<cffunction name="getTicketFields" access="public" returntype="any" hint="">
		<cfargument name="callArray">
	  <cfset var results = arrayNew(1)>
	  <cfset var myArray = arrayNew(1)>
	  <cfset var subArray = arrayNew(1)>
	  <cfset var summary = structNew()>
	  <cfset var reporter = structNew()>
	  <cfset var owner = structNew()>
	  <cfset var description = structNew()>
	  <cfset var type = structNew()>
	  <cfset var typeoptions = structNew()>
	  <cfset var status = structNew()>
	  <cfset var statusoptions = arraynew(1)>
	  <cfset var priority = structNew()>
	  <cfset var priorityoptions = arraynew(1)>
	  <cfset var milestone = structNew()>
	  <cfset var milestoneoptions = arraynew(1)>
	  <cfset var component = structNew()>
	  <cfset var componentoptions = arraynew(1)>
	  <cfset var version = structNew()>
	  <cfset var versionoptions = arraynew(1)>
	  <cfset var severity = structNew()>
	  <cfset var severityoptions = arraynew(1)>
	  <cfset var resolution= structNew()>
	  <cfset var resolutionoptions = arraynew(1)>
	  <cfset var keywords= structNew()>
	  <cfset var cc= structNew()>
	  
	  <cfset summary["type"] = "text">
	  <cfset summary["name"] = "summary">
	  <cfset summary["label"] = "summary">
		<cfset myArray = arrayAppend(myArray,summary)>
	  <cfset reporter["type"] = "text">
	  <cfset reporter["name"] = "reporter">
	  <cfset reporter["label"] = "reporter">
		<cfset myArray = arrayAppend(myArray,reporter)>
	  <cfset owner["type"] = "text">
	  <cfset owner["name"] = "owner">
	  <cfset owner["label"] = "owner">
		<cfset myArray = arrayAppend(myArray,owner)>
	  <cfset description["type"] = "textarea">
	  <cfset description["name"] = "description">
	  <cfset description["label"] = "Description">
		<cfset myArray = arrayAppend(myArray,description)>
			<cfset opops = arrayNew(1)>
			<cfset opops[1] = "defect">
			<cfset opops[2] = "enhancement">
			<cfset opops[3] = "task">
	  <cfset type["options"] = opops>
	  <cfset type["type"] = "select">
	  <cfset type["name"] = "type">
	  <cfset type["label"] = "Type">
	  <cfset type["value"] = "defect">
		<cfset myArray = arrayAppend(myArray,type)>
	  <cfset status["type"] = "radio">
	  <cfset status["name"] = "status">
	  <cfset status["label"] = "Status">
	  <cfset status["value"] = "">
	  <cfset status["optional"] = "$boolean1">
		<cfset statusoptions[1] = "new">
		<cfset statusoptions[2] = "assigned">
		<cfset statusoptions[3] = "reopened">
		<cfset statusoptions[4] = "closed">
	  <cfset status["options"] = statusoptions>
		<cfset myArray = arrayAppend(myArray,status)>

	  <cfset priority["type"] = "select">
	  <cfset priority["name"] = "priority">
	  <cfset priority["label"] = "priority">
	  <cfset priority["value"] = "normal">
	  <cfset priority["optional"] = "$boolean1">
		<cfset priorityoptions[1] = "highest">
		<cfset priorityoptions[2] = "high">
		<cfset priorityoptions[3] = "normal">
		<cfset priorityoptions[4] = "low">
		<cfset priorityoptions[4] = "lowest">
	  <cfset priority["options"] = priorityoptions>
		<cfset myArray = arrayAppend(myArray,priority)>

	  <cfset milestone["type"] = "select">
	  <cfset milestone["name"] = "milestone">
	  <cfset milestone["label"] = "milestone">
	  <cfset milestone["value"] = "">
	  <cfset milestone["optional"] = "$boolean1">
		<cfset milestoneoptions[1] = "milestone1">
		<cfset milestoneoptions[2] = "milestone2">
		<cfset milestoneoptions[3] = "milestone3">
		<cfset milestoneoptions[4] = "milestone4">
	  <cfset milestone["options"] = milestoneoptions>
		<cfset myArray = arrayAppend(myArray,milestone)>

	  <cfset component["type"] = "select">
	  <cfset component["name"] = "component">
	  <cfset component["label"] = "component">
	  <cfset component["value"] = "component1">
	  <cfset component["optional"] = "$boolean1">
		<cfset componentoptions[1] = "component1">
		<cfset componentoptions[2] = "component2">
	  <cfset component["options"] = componentoptions>
		<cfset myArray = arrayAppend(myArray,component)>

	  <cfset version["type"] = "select">
	  <cfset version["name"] = "version">
	  <cfset version["label"] = "version">
	  <cfset version["value"] = "version1">
	  <cfset version["optional"] = "$boolean1">
		<cfset versionoptions[1] = "$string2.0">
		<cfset versionoptions[2] = "$string1.0">
	  <cfset version["options"] = versionoptions>
		<cfset myArray = arrayAppend(myArray,version)>

	  <cfset severity["type"] = "select">
	  <cfset severity["name"] = "severity">
	  <cfset severity["label"] = "severity">
	  <cfset severity["value"] = "normal">
	  <cfset severity["optional"] = "$boolean1">
		<cfset severityoptions[1] = "blocker">
		<cfset severityoptions[2] = "critical">
		<cfset severityoptions[3] = "major">
		<cfset severityoptions[4] = "normal">
		<cfset severityoptions[5] = "minor">
		<cfset severityoptions[6] = "trivial">
	  <cfset severity["options"] = severityoptions>
		<cfset myArray = arrayAppend(myArray,severity)>


	  <cfset resolution["type"] = "radio">
	  <cfset resolution["name"] = "resolution">
	  <cfset resolution["label"] = "resolution">
	  <cfset resolution["value"] = "">
	  <cfset resolution["optional"] = "$boolean1">
		<cfset resolutionoptions[1] = "fixed">
		<cfset resolutionoptions[2] = "invalid">
		<cfset resolutionoptions[3] = "wontfix">
		<cfset resolutionoptions[4] = "duplicate">
		<cfset resolutionoptions[5] = "worksforme">
	  <cfset resolution["options"] = resolutionoptions>
		<cfset myArray = arrayAppend(myArray,resolution)>

	  <cfset keywords["type"] = "text">
	  <cfset keywords["name"] = "keywords">
	  <cfset keywords["label"] = "keywords">
		<cfset myArray = arrayAppend(myArray,keywords)>

	  <cfset cc["type"] = "text">
	  <cfset cc["name"] = "cc">
	  <cfset cc["label"] = "cc">
		<cfset myArray = arrayAppend(myArray,cc)>

		<cfset results[1] = myArray>

    <cfreturn results>
	</cffunction>

	<cffunction name="getTicketQuery" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="searchParams">
		<cfscript>
			var ticketIdArray = arrayNew(1);
			var dataGW = getORMService().createGateway("projecttickets");
			var query = dataGW.createquery();
			if(isArray(arguments.searchParams)) {
//				query.leftJoin("peoplememberships","people","person");
//		 	  query.returnObjectFields("people", "firstname,lastname");
			}
	 	  query.returnObjectFields("projecttickets", "ticketId");
//			query.setFieldExpression("student","student_ID","COUNT(*)","CF_SQL_INTEGER");
 			query.getWhere().isEqual("projecttickets", "projectId", arguments.projectId);
			query = dataGW.getByQuery(query);
	 	  ticketIdArray = listToArray(valueList(query.ticketId));
		</cfscript>
    <cfreturn ticketIdArray>
	</cffunction>

	<cffunction name="getTicket" access="public" returntype="any" hint="">
		<cfargument name="ticketId">
		<cfscript>
		  var ticket = arrayNew(1);
		  var attribs = structNew();
		  var rpcCall = "";
			var ticketRecord = getORMService().createRecord("projecttickets").load(ticketId=arguments.ticketId);
		</cfscript>
	  <cfset ticket[1] = "$int" & ticketRecord.getTicketId()><!--- ticketid --->
	  <cfset ticket[2] = "$int" & GetEpochTime(ticketRecord.getTicketCreated())><!--- created--->
	  <cfset ticket[3] = "$int" & GetEpochTime(ticketRecord.getTicketModified())><!--- created--->
	  <cfset attribs["status"] = "$string" & ticketRecord.getTicketStatus()>
	  <cfset attribs["description"] = "$string" & ticketRecord.getTicketDescription()>
	  <cfset attribs["reporter"] = "$string" & ticketRecord.getTicketReporter()>
	  <cfset attribs["cc"] = "$string" & ticketRecord.getTicketCC()>
	  <cfset attribs["resolution"] = "$string" & ticketRecord.getTicketResolution()>
	  <cfset attribs["component"] = "$string" & ticketRecord.getTicketComponent()>
	  <cfset attribs["summary"] = "$string" & ticketRecord.getTicketSummary()>
	  <cfset attribs["priority"] = "$string" & ticketRecord.getTicketPriority()>
	  <cfset attribs["keywords"] = "$string" & ticketRecord.getTicketKeywords()>
	  <cfset attribs["version"] = "$string" & ticketRecord.getTicketVersion()>
	  <cfset attribs["milestone"] = "$string" & ticketRecord.getTicketMilestone()>
	  <cfset attribs["owner"] = "$string" & ticketRecord.getTicketOwner()>
	  <cfset attribs["type"] = "$string" & ticketRecord.getTicketType()>
	  <cfset attribs["severity"] = "$string" & ticketRecord.getTicketSeverity()>
	  <cfset ticket[4] = attribs><!--- created--->
    <cfreturn ticket>
	</cffunction>

	<cffunction name="updateTicket" access="public" returntype="any" hint="">
		<cfargument name="params">
		<cfscript>
			var ticketRecord = getORMService().createRecord("projecttickets");
			var ticket = structNew();
			var ticketAttributes = params[3];
			ticket.ticketId = params[1];
			ticket.ticketComment = params[2];
			ticket.ticketNotifys = params[4];
			ticketRecord.load(ticketId=ticket.ticketId);
			if(ticket.ticketComment gt "") {
				ticketComment = ticketRecord.getCommentIterator().add();
				ticketComment.setCommentText(ticket.ticketComment);
				ticketComment.setCreateUserId(3); // TODO: get user id?
				ticketComment.setCreateDate(now());
			}
//			ticketRecord.setTicketOwner(ticketAttributes.owner);
			if(structKeyExists(ticketAttributes,"summary")) {
				ticketRecord.setTicketSummary(ticketAttributes.summary);
			}
			if(structKeyExists(ticketAttributes,"cc")) {
				ticketRecord.setTicketCC(ticketAttributes.cc);
			}
			if(structKeyExists(ticketAttributes,"component")) {
				ticketRecord.setTicketComponent(ticketAttributes.component);
			}
			if(structKeyExists(ticketAttributes,"description")) {
				ticketRecord.setTicketDescription(ticketAttributes.description);
			}
			if(structKeyExists(ticketAttributes,"keywords")) {
				ticketRecord.setTicketKeywords(ticketAttributes.keywords);
			}
			if(structKeyExists(ticketAttributes,"milestone")) {
				ticketRecord.setTicketMilestone(ticketAttributes.milestone);
			}
			if(structKeyExists(ticketAttributes,"priority")) {
				ticketRecord.setTicketPriority(ticketAttributes.priority);
			}
			if(structKeyExists(ticketAttributes,"severity")) {
				ticketRecord.setTicketSeverity(ticketAttributes.severity);
			}
			if(structKeyExists(ticketAttributes,"version")) {
				ticketRecord.setTicketVersion(ticketAttributes.version);
			}
			if(structKeyExists(ticketAttributes,"status")) {
				ticketRecord.setTicketStatus(ticketAttributes.status);
			}
			if(structKeyExists(ticketAttributes,"resolution")) {
				ticketRecord.setTicketResolution(ticketAttributes.resolution);
			}
			if(structKeyExists(ticketAttributes,"type")) {
				ticketRecord.setTicketType(ticketAttributes.type);
			}
			if(structKeyExists(ticketAttributes,"owner")) {
				ticketRecord.setTicketOwner(ticketAttributes.owner);
			}
			if(structKeyExists(ticketAttributes,"reporter")) {
				ticketRecord.setTicketReporter(ticketAttributes.reporter);
			}
			ticketRecord.setTicketModified(now());
			ticketRecord.save();
		</cfscript>
		<cfreturn getTicket(ticket.ticketId)>
	</cffunction>

	<cffunction name="createTicket" access="public" returntype="any" hint="">
		<cfargument name="projectId" required="true" type="numeric">
		<cfargument name="params">
		<cfscript>
			var ticketRecord = getORMService().createRecord("projecttickets");
			var ticket = structNew();
			var ticketAttributes = params[3];
			ticket.ticketSummary = params[1];
			ticket.ticketDescription = params[2];
			ticket.ticketNotifys = params[4];
			ticketRecord.load(ticketId=0);
			ticketRecord.setProjectId(arguments.projectId);
			ticketRecord.setTicketSummary(ticket.ticketSummary);
//			ticketRecord.setTicketComment(ticket.ticketComment);
//			ticketRecord.setTicketOwner(ticketAttributes.owner);
			ticketRecord.setTicketCC(ticketAttributes.cc);
			ticketRecord.setTicketComponent(ticketAttributes.component);
			ticketRecord.setTicketDescription(ticket.ticketDescription);
			ticketRecord.setTicketKeywords(ticketAttributes.keywords);
			ticketRecord.setTicketMilestone(ticketAttributes.milestone);
			ticketRecord.setTicketPriority(ticketAttributes.priority);
			ticketRecord.setTicketSeverity(ticketAttributes.severity);
			ticketRecord.setTicketType(ticketAttributes.type);
//			ticketRecord.setTicketVersion(ticketAttributes.version);
			ticketRecord.setTicketCreated(now());
			ticketRecord.setTicketModified(now());
			ticketRecord.save();
		</cfscript>
		<cfreturn ticketRecord.getTicketId()>
	</cffunction>

</cfcomponent>